/**
 * Mise en oeuvre de Piece.h
 *
 * @file Piece.cxx
 */

#include <iostream>
#include "Piece.h"
#include "Echiquier.h"
using namespace std;

Piece::Piece()
{}

Piece::Piece(int x, int y, bool white)
{
    m_x = x;
    m_y = y;
    m_white = white;
}

char Piece::tostring()
{
    return( isWhite() ? 'B' : 'N');
}

void
Piece::init( int x, int y, bool white )
{
    m_x = x;
    m_y = y;
    m_white = white;
}

void
Piece::move( int x, int y )
{

    m_x = x;
    m_y = y;
}


Piece::~Piece(){}

int
Piece::x()
{
    return m_x;
}

int
Piece::y()
{
    return m_y;
}

bool
Piece::isWhite()
{
    return m_white;
}

bool
Piece::isBlack()
{
    return !m_white;
}


void
Piece::affiche()
{
    cout << "Piece: x=" << m_x << " y=" << m_y << " "
         << ( isWhite() ? "blanche" : "noire" ) << endl;

}
bool Piece::mouvementvalide(Echiquier *e, int x, int y )
{

    if (e->getPiece(x,y) == 0)
    {
        return true;
    }
    else
    {
        if (x <= 8 && y <= 8 && x >=1 && y >= 1)
        {
            if (e->getPiece(m_x,m_y)->isWhite() != e->getPiece(x,y)->isWhite())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
}

